<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件</title>

</head>
<body>
<img id = "light" src = "img/off.gif" onclick = "fun();">

<img id = "light2" src = "img/off.gif" >

<script>
        function fun()
        {
            alert("我被点了");
        }

        var light2 = document.getElementById("light2");
        light2.onclick = fun;
        //将light2的onclick绑定fun
    </script>
</body>
</html>